package android.slc.extras.user.repository.local;

import android.slc.appbase.repository.local.DbSp;

public class UserSp {
    private final static String SP_NAME = "user";
    private final static String KEY_CURRENT_USER_ID = "currentUserId";
    private final static String KEY_CURRENT_USER_PASSWORD = "currentUserPassword";
    private final static String KEY_CURRENT_USER = "currentUser";
    private final static String KEY_IS_LOGIN = "autoLogin";
    private final static String KEY_SAVE_PASSWORD = "savePassword";
    private final static String KEY_EDIT_POW_HINT = "editPwHint";

    private final static DbSp dbSp = new DbSp(SP_NAME);

    /**
     * 获取当前保存的用户
     *
     * @return
     */
    public static long getCurrentUserId() {
        return dbSp.getLong(KEY_CURRENT_USER_ID, -1);
    }

    public static String getCurrentUserPassword() {
        return dbSp.getString(KEY_CURRENT_USER_PASSWORD);
    }

    /**
     * 获取当前保存的用户
     *
     * @return
     */
    public static String getCurrentUser() {
        return dbSp.getString(KEY_CURRENT_USER);
    }

    /**
     * 是否自动登录
     *
     * @return
     */
    public static boolean isAutoLogin() {
        return dbSp.getBoolean(KEY_IS_LOGIN, false);
    }

    /**
     * 是否保存密码
     *
     * @return
     */
    public static boolean isSavePassword() {
        return dbSp.getBoolean(KEY_SAVE_PASSWORD, true);
    }

    /**
     * 获取提示修改密码
     *
     * @return
     */
    public static boolean isEditPwHint() {
        return dbSp.getBoolean(KEY_EDIT_POW_HINT, true);
    }

    /**
     * 保存当前用户
     *
     * @param id
     */
    public static void saveCurrentUserId(long id) {
        dbSp.putValue(KEY_CURRENT_USER_ID, id);
    }

    public static void saveCurrentUserPassword(String userPassword) {
        dbSp.putValue(KEY_CURRENT_USER_PASSWORD, userPassword);
    }

    /**
     * 保存当前用户
     *
     * @param account
     */
    public static void saveCurrentUser(String account) {
        dbSp.putValue(KEY_CURRENT_USER, account);
    }

    /**
     * 自动登录
     *
     * @param isAutoLogin
     */
    public static void setAutoLogin(boolean isAutoLogin) {
        dbSp.putValue(KEY_IS_LOGIN, isAutoLogin);
    }

    /**
     * 保存密码
     *
     * @param isSavePassword
     */
    public static void setSavePassword(boolean isSavePassword) {
        dbSp.putValue(KEY_SAVE_PASSWORD, isSavePassword);
    }

    /**
     * 获取提示修改密码
     *
     * @return
     */
    public static void setEditPwHint(boolean isEditPwHint) {
        dbSp.putValue(KEY_EDIT_POW_HINT, isEditPwHint);
    }
}
